<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!-- 1.准备好一个“容器” -->
<div id="test"></div>
<!-- 引入react核心库 -->
<script src="../js/react.development.js"></script>
<!-- 引入react-dom。用于支持react操作DOM -->
<script src="../js/react-dom.development.js"></script>
<!-- 引入babel，用于将jsx转为js -->
<script src="../js/babel.min.js"></script>
<script type="text/babel">
    //创建组件
    class Demo extends React.Component {
        state = {isHot: false};
        showData = () => {
            const {input1} = this;
            alert(input1.value);
        };
        changeWeather = () => {
            // console.log('aaa');
            //获取原先的状态
            const {isHot} = this.state;
            //更新状态
            this.setState({isHot: !isHot});
        };
        saveInput = (currentNode)=>{
            this.input1 = currentNode;
            console.log('@',currentNode);
        }
        render() {
            const {isHot} = this.state;
            return (
                <div>
                    <h2>今天天气很{isHot ? "凉爽" : "炎热"}</h2>
                    {/*<input ref={(currentNode) => {
                        this.input1 = currentNode;
                        console.log('a',currentNode);
                    }} type="text"/><br/>*/}
                    <input type="text" ref={this.saveInput}/>
                    <button onClick={this.showData}>点我提示数据</button>
                    <button onClick={this.changeWeather}>点我切换天气</button>
                </div>
            );

        }
    }

    //渲染组件到页面
    ReactDOM.render(<Demo/>, document.getElementById("test"));
</script>
</body>
</html>